/**
 * @author dzmncvg
 *
 */
package vwg.na.vwm.rh.rhmotor.util;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

@ManagedBean
@ApplicationScoped
public class BooleanConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		if (arg2 == null) {
			return null;
		} else {
			if ("Si".equalsIgnoreCase(arg2)) {
				return Boolean.TRUE;
			} else if ("No".equalsIgnoreCase(arg2)) {
				return Boolean.FALSE;
			} else {
				return null;
			}
		}
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		if (arg2 == null) {
			return "";
		}
		if (((Boolean) arg2)) {
			return "Si";
		} else {
			return "No";
		}
	}
}